package cn.edu.njuit.springbootfilmreview.service.impl;

import cn.edu.njuit.springbootfilmreview.dto.MovieInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.edu.njuit.springbootfilmreview.dto.CommentInfo;
import cn.edu.njuit.springbootfilmreview.service.CommentInfoService;
import cn.edu.njuit.springbootfilmreview.mapper.CommentInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @description 针对表【comment_info(评论表)】的数据库操作Service实现
 * @createDate 2022-05-23 19:35:25
 */
@Service
public class CommentInfoServiceImpl extends ServiceImpl<CommentInfoMapper, CommentInfo>
        implements CommentInfoService {

    @Autowired
    CommentInfoMapper commentInfoMapper;

    @Override
    public boolean addCommentInfo(CommentInfo commentInfo) {
        int insert = commentInfoMapper.insert(commentInfo);
        return insert > 0;
    }

    @Override
    public boolean deleteCommentInfoById(Long id) {
        LambdaQueryWrapper<CommentInfo> lqw = new LambdaQueryWrapper<>();
        lqw.eq(CommentInfo::getId, id);
        int delete = commentInfoMapper.delete(lqw);
        return delete > 0;
    }

    @Override
    public IPage<CommentInfo> getCommentInfoByWorksId(Integer currentPage, int pageSize, Long workId) {
        LambdaQueryWrapper<CommentInfo> lqw = new LambdaQueryWrapper<>();
        lqw.eq(CommentInfo::getWorksId, workId);
        IPage page = new Page(currentPage, pageSize);
        commentInfoMapper.selectPage(page, lqw);
        return page;
    }

    @Override
    public IPage<CommentInfo> getCommentInfoByUserId(Integer currentPage, int pageSize, Long userId) {
        LambdaQueryWrapper<CommentInfo> lqw = new LambdaQueryWrapper<>();
        lqw.eq(CommentInfo::getUserId, userId);
        IPage page = new Page(currentPage, pageSize);
        commentInfoMapper.selectPage(page, lqw);
        return page;
    }
}
